using System;
using System.Collections.Generic;
using System.Text;
using RikMigrations.Providers;
using System.IO;
using NUnit.Framework;

namespace RikMigrations.Tests
{
#if SQLITE
	[TestFixture]
	public class SqliteProviderTests : DbProviderTests
	{
		string dbPath;
		SqliteProvider sqliteDb;

		public SqliteProviderTests()
			: base(new SqliteProvider())
		{
			sqliteDb = (SqliteProvider)db;
		}

		protected override void CreateSetupTestTable()
		{
			db.ExecuteNonQuery("CREATE TABLE SetupTestTable (" + SetupTestColumnName + " int)");
		}

		[SetUp]
		public override void Setup()
		{
			dbPath = Path.GetTempFileName();
			db.ConnectionString = string.Format("Data Source={0}", dbPath);

			base.Setup();
		}

		[TearDown]
		public override void TearDown()
		{
			base.TearDown();
			File.Delete(dbPath);
		}

		[Test]
		public void PrimaryKey()
		{
			Table table = db.AddTable("Test");
			Column col = table.AddColumn("ID", typeof(int)).PrimaryKey();
			Assert.IsTrue(sqliteDb.GetColumnSql(col).StartsWith("[ID] INT"));
			Assert.IsTrue(sqliteDb.GetColumnSql(col).Contains("PRIMARY KEY"));
		}

		[Test]
		public void CustomSqlType()
		{
			Table t = db.AddTable("TestTable");
			Column col = t.AddColumn("ID", null);
			col.SqlType = "faketype";
			Assert.IsTrue(sqliteDb.GetColumnSql(col).StartsWith("[ID] faketype"));
		}
	}
#endif
}